//引入路由组件
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
//引入二级路由组件
//引入组件
import myOrder from '@/pages/Center/myOrder'
import groupOrder from '@/pages/Center/groupOrder'
// console.log(VueRouter, prototype);

const foo = () => {
    return import ("@/pages/Home/index.vue")
}

//配置路由,路由的单词都是小写的
export default [{
        path: "/center",
        component: Center,
        //meta是显示底下的floor组件的
        meta: { show: true },
        //二级路由组件
        children: [{
                path: "myorder",
                component: myOrder
            },
            {
                path: "grouporder",
                component: groupOrder
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ],
    },
    {
        path: "/paysuccess",
        component: PaySuccess,
        //meta是显示底下的floor组件的
        meta: { show: true }
    },
    {
        path: "/pay",
        component: Pay,
        //meta是显示底下的floor组件的
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == "/trade") {
                next();
            } else {
                next(false);
            }
        }
    },
    {
        path: "/trade",
        component: Trade,
        //meta是显示底下的floor组件的
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == "/shopcart") {
                next();
            } else {
                next(false);
            }
        }
    },
    {
        path: "/shopcart",
        component: ShopCart,
        //meta是显示底下的floor组件的
        meta: { show: true }
    },
    {
        path: "/addcartsuccess",
        name: "addcartsuccess",
        component: AddCartSuccess,
        //meta是显示底下的floor组件的
        meta: { show: true }
    },
    {
        // 这个的路由跳转需要带参数，所以需要占位，多写一下/:skuid
        path: "/detail/:skuid",
        component: Detail,
        meta: { show: true }
    }, {
        path: "/home",
        component: Home,
        meta: { show: true }
    },
    {
        // 【这里的?表示params可传递或可不传递(和正则表达式雷同，?代表出现次数为0次或1次，即可有可无)】
        path: "/search/:keyword?",
        component: Search,
        meta: { show: true },
        name: "search",
        //路由组件能否传递props？
        // 方式一：props用布尔值，但只能传递params
        // props: true,
        // 方式二：对象写法。额外给路由组件传递一些props
        // props: { a: 1, b: 2 },
        // 方式三：函数写法。可params参数、query参数，通过props传递给路由组件
        props: ($route) => {
            return { keyword: $route.params.keyword, k: $route.query.k }
        }
    },
    {
        path: "/login",
        component: Login,
        meta: { show: false }
    },
    {
        path: "/register",
        component: Register,
        meta: { show: false }
    },
    //redirect重定向：在项目跑起来时就访问该页面(该方法可以立马让其定向到首页)
    {
        path: '*',
        redirect: './home'
    }

]